package com.zhuiyun.project.api.physician.mapper;

import com.zhuiyun.project.api.physician.entity.AppPhysician;
import com.zhuiyun.project.api.physician.model.AppPhysicianModel;

import com.zhuiyun.project.common.mapper.BaseMapper;
import com.zhuiyun.project.util.pageUtil.PageRequest;

import org.apache.ibatis.annotations.*;


import java.util.List;

@Mapper
public interface PhysicianMapper extends BaseMapper<AppPhysician> {

    /**
     * @param userId
     * @Author kdj
     * @Description 根据userId获取医师的个人信息
     * @Date 2023/8/3 16:19
     * @Return com.zhuiyun.project.api.apppatient.model.AppPhysicianLessModel
     */
    @Select("select * from app_physician  phy right join app_user on app_user.id=phy.user_id  WHERE app_user.id = #{userId}")
    AppPhysicianModel getPhyInfo(int userId);


    /**
     * 查询审核医师信息
     *
     * @return java.util.List<com.zhuiyun.project.api.physician.entity.appPhysician>
     * @author 温
     * @date 2023/6/8 10:30
     * @parameter []
     */
    @Select("<script>" +
            "select a.*,b.*, au.* from app_physician a  inner join doctor_audit b on a.user_id=b.doctor_id left join app_user au on au.id = a.user_id where au.del_flag = 0 " +
            "<if test=\"doctorName != '' and doctorName!=null\">" +
            "and au.user_name like concat('%', #{doctorName}, '%') " +
            "</if>" +
            " order by a.create_time desc" +
            "</script>")
    List<AppPhysicianModel> physicianList(@Param("doctorName") String doctorName);


    /**
     * 医师信息查询
     *
     * @return java.util.List<com.zhuiyun.project.api.physician.entity.AppPhysician>
     * @author 温
     * @date 2023/6/11 19:43
     * @parameter [nickName, pageRequest]
     */
    @Select("<script>" +
            "select a.*, au.* " +
            "from app_physician a " +
            "left join app_user au on au.id = a.user_id where au.del_flag = 0 and a.audit_status=1" +
            "<if test=\"queryUserName != '' and queryUserName!=null\">" +
            "and au.user_name like concat('%', #{queryUserName}, '%') " +
            "</if>" +
            "</script>")
    List<AppPhysicianModel> PhysicianListState(@Param("queryUserName") String queryUserName);

    /**
     * @param id
     * @Author kdj
     * @Description 注销医生管理账号
     * @Date 2023/8/4 14:11
     * @Return int
     */
    @Update("update app_physician set del_flag=1 where id=#{id}")
    int PhysicianUpdate(Integer id);


    /**
     * 恢复注销的医生管理
     *
     * @return int
     * @author 温
     * @date 2023/6/15 14:54
     * @parameter [id]
     */
    @Update("update  app_physician set del_flag=0 where id=#{id}")
    int doctorRestore(int id);


    /**
     * 彻底删除注销的医生账号
     *
     * @return int
     * @author 温
     * @date 2023/6/15 14:59
     * @parameter [id]
     */
    @Delete("delete  from app_physician where id=#{id} ")
    int doctorRestoreDelete(int id);


    /**
     * 查询注销的医生信息
     *
     * @return java.util.List<com.zhuiyun.project.api.physician.entity.AppPhysician>
     * @author 温
     * @date 2023/6/11 19:43
     * @parameter [nickName, pageRequest]
     */
    @Select("select* from app_physician where  doctor_name like '%${doctorName}%' and  del_flag=1")
    List<AppPhysician> doctorLogOff(@Param("doctorName") String doctorName, @Param("PageRequest") PageRequest pageRequest);

    /**
     * @param userId
     * @Author kdj
     * @Description 审核通过成为医师
     * @Date 2023/8/5 22:06
     * @Return int
     */
    @Update("UPDATE app_physician set audit_status = 1 , update_time=now() where user_id = #{userId}")
    int userToPhy(Integer userId);
    /**
     * @param userId
     * @Author kdj
     * @Description 审核不通过成为医师
     * @Date 2023/8/5 22:06
     * @Return int
     */
    @Update("UPDATE app_physician set audit_status =2, update_time=now() where user_id = #{userId}")
    int userToPhyNo(Integer userId);
    /**
     * @param id
     * @Author ys
     * @Description 根据医师id获取userid
     * @Date 2023/8/3 16:19
     * @Return com.zhuiyun.project.api.apppatient.model.AppPhysicianLessModel
     */
    @Select("select user_id from app_physician WHERE id= #{id}")
    int getPhysicianUserid( @Param("id") int id);

}
